<?
/**
 * VoiceOne Settings/Meetme/edit
 *
 * Frontend to provide access to the meetme system in voiceone.
 * @package voiceone
 * @subpackage  settings_meetme
 */
  include ("../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  sajax_init();
  //================ PAGE LOGIC ================
  if (count($_POST)>0) {

    // create the entry array with the posted data  

    $entry=Array(
      "id"        => $_POST["id"],
      "confno"    => $_POST["confno"],
      "pin"       => $_POST["pin"],
      "adminpin"  => $_POST["adminpin"], 
    ); 

    // attach some application parameter

    $entry["application"]["macro"]     = $_POST["macro"];    

    // merge the macro parameter

    if (is_array($_POST["macro_param"]))
      foreach ($_POST["macro_param"] as $k=>$v) $p.="$k=$v|";
    $p=substr($p,0,-1);

    $entry["application"]["parameter"] = $p;
    $entry["application"]["groups"]    = $_POST["groups"];    

    $ret=$asterisk->putMeetme($entry);

    if ($ret>0) {
      $alert="<div class=\"AlertGood\">".$cwlang["meetme"]["alertModGood"]."</div>";
      $_GET["id"]=$ret;
    } else $alert="<div class=\"AlertBad\">".$cwlang["meetme"]["alertModBad"]."</div>";

    goToMainPage($alert);
  }

  
  // retrieve the meetme informations

  if ($_GET["id"] != "") {
    $meetme   = $asterisk->getMeetme($_GET["id"]);
    $confno   = $meetme[0]["confno"];
    $pin      = $meetme[0]["pin"];
    $adminpin = $meetme[0]["adminpin"];
    $app_id   = $meetme[0]["app_id"];
    $app_name = $meetme[0]["app_name"];
    $macro    = $meetme[0]["application"][0]["macro"];
    $parameter= $meetme[0]["application"][0]["parameter"];
    $groups   = $meetme[0]["application"][0]["groups"];
    $title    = $cwlang["meetme"]["modifyMeetme"].$confno;
  } else {
    $confno   = "";
    $pin      = "";
    $adminpin = "";
    $title    = $cwlang["meetme"]["newMeetme"];
  }
  
  //================ MAIN CONTENTS ================
  ob_start();
  ?>
  <div class="SectionHeader">
  <?=$alert?>
    <h1><?=$title?></h1>
    <h3>
      <a href="../" class="admin" ><?=$cwlang["meetme"]["return"]?></a>
    </h3>
  </div>

  <div id="basic_form">
    <form action="<?=$PHP_SELF?><? if ($_GET["id"]!="") echo "?id=".$_GET["id"]; ?>" method="post">
      
      <div id="client_form" >
         <h2><?=$cwlang["meetme"]["titleForm"]?></h2>  
        <p class="blockintro"><?=$cwlang["meetme"]["textForm"]?></p>
        <div class="block">
          <dl>
            <dt class="required"><label for="confno"><?=$cwlang["meetme"]["confno"]?>:</label></dt> 
            <dd><input type="text" size="25" maxlength="30" id="confno" name="confno" value="<?=$confno?>" /></dd>
            <?=$cwlang["meetme"]["confnoExample"]?>
          </dl>
          <dl>
            <dt class="required"><label for="pin"><?=$cwlang["meetme"]["pin"]?>:</label></dt>
            <dd><input type="text" size="25" maxlength="30" id="pin" name="pin" value="<?=$pin?>" /></dd>
            <?=$cwlang["meetme"]["pinExample"]?>
          </dl>
          <dl>
            <dt class="required"><label for="adminpin"><?=$cwlang["meetme"]["adminpin"]?>:</label></dt>
            <dd><input type="text" size="25" maxlength="30" id="adminpin" name="adminpin" value="<?=$adminpin?>" /></dd>
            <?=$cwlang["meetme"]["adminpinExample"]?>
          </dl>
          <table class="todolist" >
            <tr><?=$html?></tr>
          </table>
        </div>
        <input type="hidden" name="id" value="<?=$id?>" />
      </div>      

      <?echo listMacro($js, $macro, $parameter);?>      

      <?echo listGroup(GROUP_OF_APPLICATION, $js, $groups);?>      
      
      <div class="action">
        <?if ($_GET["id"]!="") {?><input type="hidden" name="meetme[id]" value="<?=$_GET["id"]?>" /><?}?>
        <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-cancel.gif" alt="Annulla" onclick="location.href='../'; return false;"/>
        <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-save.gif" alt="Salva" />
      </div>
    </form>
  </div>  
  
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
        <div class="Sidebar">
          <h1><?=$cwlang["meetme"]["sidebarEditTitle"]?></h1>
          <?=$cwlang["meetme"]["sidebarEditText"]?>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================
 	sajax_handle_client_request();

  $smarty->assign("section", "meetme");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->assign("ajax", $js);
  $smarty->display('settings.tpl');

?>
